﻿using Furion;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using HiSport.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace HiSport.Application.Text.Service
{
    public class TestService : ITestService, ITransient
    {

        public readonly ISqlSugarClient _dbContext;
        public TestService(ISqlSugarClient dbContext)
        {
            _dbContext = dbContext;
        }

        /// <summary>
        /// CodeFirst
        /// </summary>
        /// <returns></returns>
        public Task<bool> CodeFirst()
        {
            

            var types = Assembly.Load("HiSport.Core").GetTypes()
                .Where(x => x.GetCustomAttribute<SugarTable>() != null
                            && x.Namespace == "HiSport.Core.Entity").ToArray();

            ////静态获取
            //SqlSugarDb.Db.CodeFirst.InitTables(types);

            //注入
            _dbContext.CodeFirst.InitTables(types);

            ////全局获取
            //App.GetService<ISqlSugarClient>().CodeFirst.InitTables(types);

            return Task.FromResult(true);
        }

        public async  Task<string> CodeSecond(string id)
        {
            return id;
        }
    }
}
